package com.hcy.asyncfiledownload.datamodule.service.provider;

import com.hcy.asyncfiledownload.datamodule.annotion.ProviderType;
import com.hcy.asyncfiledownload.datamodule.service.provider.ExportHandler;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author huchenying
 * @Date 2022/9/6 16:03
 * @Description 一个provider仓库，存储和获取provider
 */
public class CenterHandler {

    private static final Map<ProviderType, ExportHandler> providerStore = new HashMap<>();

    public static ExportHandler getProvider(ProviderType providerType) {
        ExportHandler exportHandler = providerStore.get(providerType);
        if (exportHandler == null) {
            throw new RuntimeException("provider not found");
        }
        return exportHandler;
    }

    public static void setProvider(ProviderType type, ExportHandler handler) {
        providerStore.put(type, handler);
    }
}
